﻿/**
* @see http://github.com/NV/placeholder.js
*/

(function ($) {

    $.fn.placeholder = function () {

        return this.each(function () {

            var that = this;

            if (that.placeholder && 'placeholder' in document.createElement(that.tagName)) return;
            var input = $(that);
            var placeholder = input.attr('placeholder');

            if (that.value === '' || that.value == placeholder) {
                input.addClass('placeholder');
                that.value = placeholder;
            }

            input.focus(function () {
                if (input.hasClass('placeholder')) {
                    this.value = '';
                    input.removeClass('placeholder');
                }
            })
            .blur(function () {
                if (this.value === '') {
                    input.addClass('placeholder');
                    this.value = placeholder;
                } else {
                    input.removeClass('placeholder');
                }
            });

            that.form && $(that.form).submit(function () {
                if (input.hasClass('placeholder')) {
                    that.value = '';
                }
            });

        });

    };

})(jQuery);
